/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Dashboard.java
 *
 * Created on 12-nov-2011, 13:58:19
 */
/**
 *
 * @author Usuario
 */
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import java.util.ArrayList;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Dashboard extends javax.swing.JFrame {

    /** Creates new form Dashboard */
    public Dashboard() {
        initComponents();
    }
    
    DefaultListModel listmodelo = new DefaultListModel();

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        NewEntryButton = new javax.swing.JButton();
        SettingsButton = new javax.swing.JButton();
        jFileChooser1 = new javax.swing.JFileChooser();
        SearchField = new javax.swing.JTextField();
        SearchButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        MainList = new javax.swing.JList();
        CategoriesDropDown = new javax.swing.JComboBox();
        SignOutButton = new javax.swing.JButton();
        Generate = new javax.swing.JButton();

        NewEntryButton.setText("Nuevo registro");
        NewEntryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NewEntryButtonActionPerformed(evt);
            }
        });

        SettingsButton.setText("Configuraciones");
        SettingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SettingsButtonActionPerformed(evt);
            }
        });

        SearchField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchFieldActionPerformed(evt);
            }
        });

        SearchButton.setText("Buscar");

        MainList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                MainListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(MainList);

        CategoriesDropDown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "(Seleccione una categoría)", "Candados con combinación", "Automóviles", "Cuentas informáticas", "Cuentas bancarias", "Tarjetas de crédito/débito" }));
        CategoriesDropDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CategoriesDropDownActionPerformed(evt);
            }
        });

        SignOutButton.setText("Cerrar sesión");
        SignOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SignOutButtonActionPerformed(evt);
            }
        });

        Generate.setText("Generar");
        Generate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GenerateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(NewEntryButton)
                .addGap(18, 18, 18)
                .addComponent(SettingsButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SignOutButton)
                .addContainerGap(48, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                        .addGap(34, 34, 34))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(CategoriesDropDown, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(SearchField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(SearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Generate))
                        .addGap(34, 34, 34))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SearchButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CategoriesDropDown, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Generate))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NewEntryButton)
                    .addComponent(SettingsButton)
                    .addComponent(SignOutButton))
                .addGap(28, 28, 28))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    DefaultListModel dashlist = new DefaultListModel();
    static ArrayList<DataOperations> entries = new ArrayList();
    
    private void SettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SettingsButtonActionPerformed
        // TODO add your handling code here:
        Settings toSettings = new Settings();
        toSettings.setLocationRelativeTo(null);
        toSettings.setVisible(true);
    }//GEN-LAST:event_SettingsButtonActionPerformed

    private void SearchFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SearchFieldActionPerformed

    private void NewEntryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewEntryButtonActionPerformed
        // TODO add your handling code here:
        NewEntry toNewEntry = new NewEntry();
        toNewEntry.setLocationRelativeTo(null);
        toNewEntry.setVisible(true);
    }//GEN-LAST:event_NewEntryButtonActionPerformed

    private void CategoriesDropDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategoriesDropDownActionPerformed
        // TODO add your handling code here:        
        
    }//GEN-LAST:event_CategoriesDropDownActionPerformed
    
    public void cargarDatos() throws FileNotFoundException {
            //Carga de datos para nuevos datos
            Scanner dataDatos = new Scanner(new FileReader ("C:/Users/UsuarioDownloads/Laboratorio #7.txt"));
            while (dataDatos.hasNext()){
                this.listmodelo.addElement(dataDatos.nextLine());
            }
        }

    private void SignOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SignOutButtonActionPerformed
        // TODO add your handling code here:
        MainScreen signout = new MainScreen();
        signout.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_SignOutButtonActionPerformed

    private void MainListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_MainListValueChanged
        // TODO add your handling code here:    
    }//GEN-LAST:event_MainListValueChanged

    private void GenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GenerateActionPerformed
        // TODO add your handling code here:
        int choice = CategoriesDropDown.getSelectedIndex();
        listmodelo.removeAllElements();
        switch(choice){
            case 1:
                Scanner dataDatos = null;
        try {
            dataDatos = new Scanner(new FileReader ("C:/Users/Dj Freddy/Desktop/Laboratorio #7.txt"));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Dashboard.class.getName()).log(Level.SEVERE, null, ex);
        }
            while (dataDatos.hasNext()){
                this.listmodelo.addElement(dataDatos.nextLine());
            }
                MainList.setModel(listmodelo);
        }
    }//GEN-LAST:event_GenerateActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Dashboard().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox CategoriesDropDown;
    private javax.swing.JButton Generate;
    private javax.swing.JList MainList;
    private javax.swing.JButton NewEntryButton;
    private javax.swing.JButton SearchButton;
    private javax.swing.JTextField SearchField;
    private javax.swing.JButton SettingsButton;
    private javax.swing.JButton SignOutButton;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
